agentmux_srv\backend\history/
adapter.rs1use serde::{Deserialize, Serialize};
7
8#[derive(Debug)]
10pub enum HistoryError {
11 Io(std::io::Error),
12 Json(serde_json::Error),
13 Other(String),
14}
15
16impl std::fmt::Display for HistoryError {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 match self {
19 HistoryError::Io(e) => write!(f, "IO error: {}", e),
20 HistoryError::Json(e) => write!(f, "JSON error: {}", e),
21 HistoryError::Other(s) => write!(f, "{}", s),
22 }
23 }
24}
25
26impl From<std::io::Error> for HistoryError {
27 fn from(e: std::io::Error) -> Self {
28 HistoryError::Io(e)
29 }
30}
31
32impl From<serde_json::Error> for HistoryError {
33 fn from(e: serde_json::Error) -> Self {
34 HistoryError::Json(e)
35 }
36}
37
38pub struct DiscoveredFile {
40 pub file_path: String,
41 pub mtime_ms: i64,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct SessionMeta {
47 pub session_id: String,
48 pub file_path: String,
49 pub provider: String,
50 pub model: String,
51 pub slug: String,
52 pub working_directory: String,
53 pub created_at: i64,
54 pub modified_at: i64,
55 pub message_count: u32,
56 pub first_user_message: String,
57 pub file_size_bytes: u64,
58 pub git_branch: String,
59 pub total_tokens: u64,
60 pub subagent_count: u32,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct HistorySession {
66 pub meta: SessionMeta,
67 pub messages: Vec<HistoryMessage>,
68}
69
70#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct HistoryMessage {
73 pub role: String,
74 pub content: String,
75 pub timestamp: i64,
76 pub tool_uses: Vec<ToolUseSummary>,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct ToolUseSummary {
82 pub name: String,
83 pub argument_summary: String,
84}
85
86pub trait HistoryAdapter: Send + Sync {
88 fn provider(&self) -> &str;
90
91 fn discover_files(&self) -> Result<Vec<DiscoveredFile>, HistoryError>;
94
95 fn extract_meta(&self, file_path: &str) -> Result<Option<SessionMeta>, HistoryError>;
97
98 fn parse_file(&self, file_path: &str) -> Result<Option<HistorySession>, HistoryError>;
100}